<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- 定义项目路径   url标签可以  -->
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>伊翔分销平台-公告添加</title>
<!-- 引入jQuery -->
<script src="${ctx}/jslib/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>

<script src="${ctx }/jslib/jquery.form.js" type="text/javascript"></script> 
    <script type="text/javascript" charset="utf-8">
        //window.UEDITOR_HOME_URL = "${ctx}/ueditor/";
    </script>
    <script type="text/javascript" charset="utf-8" src="${ctx }/jslib/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx }/jslib/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript">
 
$(document).ready(function(){
	  
	  var ajaxFormOption = {
           type: "post",  //提交方式  
           dataType: "json", //数据类型  
           url: "${ctx}/notice/update", //请求url
           success: function (data) { //提交成功的回调函数
           	  if(data.success){
           		layer.alert('修改成功！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
        		  	$("#user_form_0")[0].reset();  
        		  	window.location.href="${ctx}/np/notice";
				    layer.close(index);
				});
           	  }else{
           		layer.alert(data.msg,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
				    layer.close(index);
				});
           	  }
           },
           error:function(){
        	  alert("网络错误，请稍后再试");
           }
       };
	  //不需要submit按钮，可以是任何元素的click事件
       $("#user_submit").click(function () {
           $("#content").val(UE.getEditor('editor').getContent());
           var temp = checkform();
    	   if(temp){
    		   $("#user_form_0").ajaxSubmit(ajaxFormOption);
    	   }
           return false;
       });
}) 
</script>
</head>

<body>
<jsp:include page="../head.jsp"></jsp:include>
<div  class="divBox">
<form id="user_form_0" class="user_form" method="post" action="${ctx }/user/reg">
    <table border="0" style="margin-top:10px;">
        <tr height="40">
            <td align="center" width="100px">标题</td>
            <td ><input id="title" class="user_input" type="text" style="width:98%" name="title" value="${notice.title }"></td>
        </tr>
        <tr>
            <td colspan="2">
                <script id="editor" type="text/plain" style="width:100%;height:500px;">${notice.content }</script>
                <input id="content" class="user_input" type="hidden" name="content" value="" >
                <input id="id" class="user_input" type="hidden" name="id" value="${notice.id }" >
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input name="提交" type="button" class="query" id="user_submit" value="保存">
            </td>
        </tr>
    </table>
</form>

</div>
<script type="text/javascript">
UE.getEditor('editor');
function checkform(){
	 $("#content").val(UE.getEditor('editor').getContent());
		if(jQuery.trim($("#title").val())==''){
			alert("标题不能为空！");
			return false;
		}
		 
		if(jQuery.trim($("#content").val())==''){
			alert("内容不能为空！");
			return false;
		}
		return true;
	 }
</script>
</body>
</html>
